#include <cstdio>
#include <utility>
using namespace std;

const int maxn = 100005;
int n, m, kase, list_left[maxn], list_right[maxn];

inline void link(int, int);

int main() {
  while (scanf("%d %d\n", &n, &m) == 2) {
    for (int i = 1; i <= n; i++) {
      list_left[i] = i - 1;
      list_right[i] = (i + 1) % (n + 1);
    }
    list_left[0] = n;
    list_right[0] = 1;

    int op, x, y, inverse = 0;
    while (m--) {
      scanf("%d", &op);
      if (op == 4) {
        inverse = !inverse;
      }
      else {
        scanf("%d %d", &x, &y);
        if (op == 3 && list_right[y] == x) { /* 3 3(x) 4(y) v.s. 3 4(x) 3(y), case 1's x_left = 2, but case 2's x_left = 3, so we use swap, the result will be same below. */
          swap(x, y);
        }
        if (op != 3 && inverse) {
          /* 3 - 1 = 2, 3 - 2 = 1 */
          op = 3 - op;
        }
        if (op == 1 && list_left[y] == x) {
          continue;
        }
        if (op == 2 && list_right[y] == x) {
          continue;
        }

        int x_left = list_left[x], x_right = list_right[x], y_left = list_left[y], y_right = list_right[y];
        if (op == 1) {
          link(x_left, x_right);
          link(y_left, x);
          link(x, y);
        }
        else if (op == 2) {
          link(x_left, x_right);
          link(x, y_right);
          link(y, x);
        }
        else if (op == 3) {
          if (list_right[x] == y) {
            link(x_left, y);
            link(x, y_right);
            link(y, x);
          }
          else {
            link(x_left, y);
            link(y, x_right);
            link(y_left, x);
            link(x, y_right);
          }
        }
      }
    }

    int v = 0;
    long long sum = 0;
    for (int i = 1; i <= n; i++) {
      /* from left to right */
      v = list_right[v];
      if (i & 1) {
        sum += v;
      }
    }
    if (inverse && (!(n & 1))) {
      sum = (long long)n * (n + 1) / 2 - sum;
    }
    printf("Case %d: %lld\n", ++kase, sum);
  }
  return 0;
}

inline void link(int left, int right) {
  list_left[right] = left;
  list_right[left] = right;
}
